package com.wdciti.sccp.iot.springvertx.configure;


import com.wdciti.sccp.iot.common.endpoint.EndpointConfig;
import com.wdciti.sccp.iot.common.endpoint.EndpointType;
import com.wdciti.sccp.iot.common.endpoint.UseEndpoint;
import com.wdciti.sccp.iot.springvertx.protocols.mqtt.MqttClientEndpointConfig;
import com.wdciti.sccp.iot.springvertx.protocols.mqtt.SimpleMqttVerticle;
import com.wdciti.sccp.iot.springvertx.protocols.tcp.SimpleTcpServerVerticle;
import com.wdciti.sccp.iot.springvertx.protocols.tcp.TcpEndpointConfig;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

/**
 * @author by early
 */
@AutoConfigureOrder(103)
@VerticleConfig
public class VerticleAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "ely.iot.endpoints.tcp-server.simple")
    @UseEndpoint(endpointBean = "simpleTcpServerVerticle", endpointClass = SimpleTcpServerVerticle.class)
    EndpointConfig simpleTcpServerConf() {
        return new TcpEndpointConfig().build("simple", EndpointType.TCP_SERVER);
    }

    @Bean
    @Scope(value = SCOPE_PROTOTYPE)
    SimpleTcpServerVerticle simpleTcpServerVerticle() {
        return new SimpleTcpServerVerticle();
    }


    @Bean
    @ConfigurationProperties(prefix = "ely.iot.endpoints.mqtt.simple")
    @UseEndpoint(endpointClass = SimpleMqttVerticle.class)
    EndpointConfig simpleMqttClientConf() {
        return new MqttClientEndpointConfig().build("simpleMqtt", EndpointType.MQTT_CLIENT);
    }

    @Bean
    @Scope(value = SCOPE_PROTOTYPE)
    SimpleMqttVerticle simpleMqttVerticle() {
        return new SimpleMqttVerticle();
    }


}
